﻿namespace 设备报警系统客户端
{
    public partial class 验证服务 : Form
    {
        public 验证服务()
        {
            InitializeComponent();
            // 在窗体加载时将ControlBox设置为false来隐藏关闭按钮
            this.ControlBox = false;
        }

        Bitmap captchaImage;
        string verificationCode = "123456";

        private void 验证服务_Load(object sender, EventArgs e)
        {
            // 生成验证码图片和验证键  
            VerificationServices.Start(out captchaImage, out verificationCode);

            try
            {
                pbVerificationCode.Image = captchaImage;
                //pbVerificationCode.Image = VerificationServices.GetPicture(Color.Lime);
            }
            catch (Exception)
            {

            }

            tbVerificationCode.Focus();
        }

        private void btnConfirm_Click(object sender, EventArgs e)
        {
            if (tbVerificationCode.Text.Length > 2)
            {
                if (tbVerificationCode.Text == verificationCode)
                {

                    DialogResult = DialogResult.OK;
                    this.Close();
                    captchaImage!.Dispose();
                }
                else
                {
                    MessageBox.Show("验证错误，验证失败！", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    tbVerificationCode.Text = "";
                }
            }
            else
            {
                MessageBox.Show("验证码输入错误/未输入", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
                tbVerificationCode.Text = "";
            }
        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            DialogResult = DialogResult.Cancel;

            this.Close();
        }
    }
}
